<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
    <!--    <style>th{min-width: unset !important;}</style>-->
</head>
<body class='labelAuto'>
<div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">审批</a>
            <a href="javascript:;">审批</a>
            <a><cite>考勤</cite></a>
        </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right:10px"
       onclick="window.history.go(-1)" title="后退">
        <i class="iconfontBlod" style="line-height:30px">&#xe74f;</i>
    </a>
</div>
<div class="layui-fluid attendance">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body search">
                    <form action="" class="layui-form livingList">
                        <div class="layui-form-item">
<!--                            <div class="layui-inline">-->
<!--                                <label class="layui-form-label">项目</label>-->
<!--                                <div class="layui-input-block">-->
<!--                                    <select name="" id="project">-->
<!--                                        <option value="">-</option>-->
<!--                                    </select>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="layui-inline">-->
<!--                                <button class="layui-btn search" type="button" id='search'>-->
<!--                                    <i class="iconfont layui-icon">&#xe615;</i>-->
<!--                                </button>-->
<!--                            </div>-->
                        </div>
                    </form>
                </div>
                <div class="layui-card-body tableCardBody">
                    <table class="layui-table" id="lists" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var approvalId = getQueryString('approvalId');
        var projectId = getQueryString('projectId');
        var professionId = getQueryString('professionId');
        var data = [];
        $.ajax({
            url: url + "/approval/approval/approvalDataAttendance",
            type: "POST",
            async: false,
            data: {
                projectId: projectId,
                professionId: Number(professionId),
                approvalId:approvalId,
                token: getToken()
            },
            success: function (r) {
                if (r.code == 100000) {
                    data = r.data;
                } else {
                    tips('审核', r);
                }
            }
        });
        // var days = (new Date(month.substr(0,4), month.substr(5,2), 0)).getDate();
        var endDate = new Date(data.endTime);
        var tmpDate = new Date(data.startTime);
        var column = [ //表头
            {field: '', title: '编号', type: 'numbers',width:60,fixed:'left'},
            {field: 'name', title: '姓名',width:80,fixed:'left'},
            {field: 'jobNumber', title: '工号',width:90,fixed:'left'},
            {field: 'professionName', title: '工种',width:90,fixed:'left'},
            {field: 'projectName', title: '现属项目',width:180,fixed:'left'},
            {
                field: 'status', title: '状态',width:60,fixed:'left', templet(d) {
                    return d.status == 1 ? "在岗" : d.status == 2 ? "待岗" : d.status == 3 ? "请假" : d.status == 4 ? "离职" : "";
                }
            },
            // { field: 1, title: 1,templet:function(d){return d.attendance[1]}},
            // { field: 2, title: 2,templet:function(d){return d.attendance[2]}},
            // { field: 3, title: 3,templet:function(d){return d.attendance[3]}},
            // { field: 4, title: 4,templet:function(d){return d.attendance[4]}},
            // { field: 5, title: 5,templet:function(d){return d.attendance[5]}},
            // { field: 6, title: 6,templet:function(d){return d.attendance[6]}},
            // { field: 7, title: 7,templet:function(d){return d.attendance[7]}},
            // { field: 8, title: 8,templet:function(d){return d.attendance[8]}},
            // { field: 9, title: 9,templet:function(d){return d.attendance[9]}},
            // { field: 10, title: 10,templet:function(d){return d.attendance[10]}},
            // { field: 11, title: 11,templet:function(d){return d.attendance[11]}},
            // { field: 12, title: 12,templet:function(d){return d.attendance[12]}},
            // { field: 13, title: 13,templet:function(d){return d.attendance[13]}},
            // { field: 14, title: 14,templet:function(d){return d.attendance[14]}},
            // { field: 15, title: 15,templet:function(d){return d.attendance[15]}},
            // { field: 16, title: 16,templet:function(d){return d.attendance[16]}},
            // { field: 17, title: 17,templet:function(d){return d.attendance[17]}},
            // { field: 18, title: 18,templet:function(d){return d.attendance[18]}},
            // { field: 19, title: 19,templet:function(d){return d.attendance[19]}},
            // { field: 20, title: 20,templet:function(d){return d.attendance[20]}},
            // { field: 21, title: 21,templet:function(d){return d.attendance[21]}},
            // { field: 22, title: 22,templet:function(d){return d.attendance[22]}},
            // { field: 23, title: 23,templet:function(d){return d.attendance[23]}},
            // { field: 24, title: 24,templet:function(d){return d.attendance[24]}},
            // { field: 25, title: 25,templet:function(d){return d.attendance[25]}},
            // { field: 26, title: 26,templet:function(d){return d.attendance[26]}},
            // { field: 27, title: 27,templet:function(d){return d.attendance[27]}},
            // { field: 28, title: 28,templet:function(d){return d.attendance[28]}},
            // { field: 29, title: 29,templet:function(d){return d.attendance[29]}},
            // { field: 30, title: 30,templet:function(d){return d.attendance[30]}},
            // { field: 31, title: 31,templet:function(d){return d.attendance[31]}},
        ];

        var i= 1;
        while(tmpDate <= endDate){
            column.push({ field: tmpDate.getDate(), title: tmpDate.getDate(),templet:function(d){return columnCallBack(d,7)}});
            i++;
            tmpDate = new Date(tmpDate.setDate(tmpDate.getDate()+1))
        }
        column.push({
            field: 'sum', title: '汇总', width: 70, templet: function (d) {
                var sum = 0;
                for (var i in d.attendance) {
                    if (d.attendance[i].projectId == projectId){
                        sum += Number(d.attendance[i].long);
                    }
                }
                return `<span title="" class='currProject'>${sum}</span>`;
            }
        },)
        var lists = table.render({
            elem: '#lists', //绑定DOM元素
            id: 'lists', //table的id
            title: '人员列表',
            height: 'full-150',
            toolbar: '#toolbar',
            defaultToolbar: ['filter','exports'],
            page: false, //开启分页
            limit: 10, //默认每页记录条数
            limits: [10, 20, 50], //每页记录条数可选数量
            data:data.data,
            cols: [
                column
            ],
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 100000, //成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            }
        });

        table.on('tool(test)',function(data){
            if(data.event=='reject'){
                var id = data.data.id;
                $.ajax({
                    url:url+'/approval/attendance/reject',
                    type:"post",
                    data:{
                        employeeId:Number(id),
                        projectId:projectId,
                        month:month,
                        token:getToken()
                    },
                    success:function(r){
                        if(r.code==100000){
                            table.reload('lists');
                        }else{
                            tips('审批',r);
                        }
                    }
                })
            }
        })
		function columnCallBack(d,i){
            return `<span title="${d.attendance[i].projectName}">${d.attendance[i].long}</span>`
        }
    });
</script>

</html>